package com.myslef.teaching_platfrom.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.myslef.teaching_platfrom.domain.users.User;
import com.myslef.teaching_platfrom.mapper.UserMapper;
import com.myslef.teaching_platfrom.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.sql.Timestamp;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;
    public Integer updateUserPassword(String email, String password) {
        LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(User::getEmail, email)
                .set(User::getPassword, DigestUtils.md5DigestAsHex(password.getBytes()))
                .set(User::getUpdate_time, new Timestamp(System.currentTimeMillis()));
        int update = userMapper.update(null, wrapper);
        return update;
    }

    public List<String> selectPic(String url){
        return baseMapper.selectPic(url);
    }

}
